﻿/*
文件名称：share.js
创建人员：刘扬
创建日期：2012-01-11
文件说明：提供将网页分享到相关门户和社交网站的客户端js接口
*/

var shareurl = "http://www.uknow.org.cn/cn/home.html";                // 默认分享URL，如果用户分享的URL有问题，则分享该URL
var sharepic = "http://www.uknow.org.cn/cn/images/UK_logo.gif";            // 默认分享图片，如果用户分享的图片有问题，则分享该图片
var domainName = "http://www.uknow.org.cn/";
function getshareurl(url) {
    if (url == null || typeof url == "undefined") {
        return shareurl;
    }
    return url;
}

function getsharepic(pic) {
    if (pic == null || typeof pic == "undefined") {
        return sharepic;
    }
    return pic;
}

function shareWindow(url, params) {
    this.params = params;
    this.url = url;

    this.getOpenUrl = function () {
        var arr = [];
        var params = this.params;
        for (var tmp in params) {
            arr.push(tmp + '=' + (tmp.toLowerCase()=='pic' ? params[tmp] : encodeURIComponent(params[tmp] || '')));
        }
        var url = this.url + '?' + arr.join('&');
        return url;
    };

    this.open = function () {
        var url = this.getOpenUrl();
        var winArgs = 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes';
        window.open(url, '_blank', winArgs);
        void (0);
    };
}

//豆瓣
function sharedouban(title, content, pic, url) {
    //url = getshareurl(url);
    var params = {
        url: location.href,
        title: title
    };
    var sUrl = 'http://www.douban.com/recommend/';
    var win = new shareWindow(sUrl, params);
    win.open();
    //window.open('http://www.douban.com/recommend/?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title), '_blank', 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
    //void (0);
}

//开心 
function sharekaixin001(title, content, pic, url) {
    url = getshareurl(url);
    pic = getsharepic(pic);
//    window.open('http://www.kaixin001.com/repaste/share.php?rtitle=' + encodeURIComponent(title) + '&rurl=' + encodeURIComponent(url) + '&rcontent=' + encodeURIComponent(content) + '&pic=' + pic, '_blank', 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
//    void (0);

    var sUrl = 'http://www.kaixin001.com/repaste/share.php';
    var params = {
        rurl: location.href,
        rtitle: title,
        rcontent: content,
        pic: pic
    };
    var win = new shareWindow(sUrl, params);
    win.open();
}

//人人 
function sharerenren(title, content, pic, url) {
    url = getshareurl(url);
    pic = getsharepic(pic);
//    window.open('http://share.renren.com/share/buttonshare.do?link=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&content=' + encodeURIComponent(content) + '&pic=' + pic, '_blank', 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
//    void (0);

    var sUrl = 'http://share.renren.com/share/buttonshare.do';
    var params = {
        link: location.href,
        title: title,
        content: content,
        pic: pic
    };
    var win = new shareWindow(sUrl, params);
    win.open();
}

//QQ 
function shareqq(title, content, pic, url) {
    url = getshareurl(url);
    pic = getsharepic(pic);
//    window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&content=' + encodeURIComponent(content), '_blank', 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
//    void (0);

    var sUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey';
    var params = {
        url: location.href,
        content: content,
        title: title
    };
    var win = new shareWindow(sUrl, params);
    win.open();
}

//搜狐 
function shareshou(title, content, pic, url) {
    url = getshareurl(url);
    pic = getsharepic(pic);
    if (content == null || content == "") {
        content = title;
    }
//    window.open('http://t.sohu.com/third/post.jsp?title=' + encodeURIComponent(content) + '&url=' + encodeURIComponent(url) + '&pic=' + pic + "&content=utf-8", '_blank', 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
//    void (0);

    var sUrl = 'http://t.sohu.com/third/post.jsp';
    var params = {
        url: location.href,
        title: content,
        pic: pic,
        content: 'utf-8'
    };
    var win = new shareWindow(sUrl, params);
    win.open();
}

//新浪微博 
function sharesina(content, pic, url) {
    url = getshareurl(url);
    pic = getsharepic(pic);
//    fpic = "http://uknow.ogilvy.com.cn/uploadfiles/image/b93e0998-5698-4086-9a15-7960120931a7.JPG";
//    var appkey = "1509936684";
//    window.open('http://v.t.sina.com.cn/share/share.php?title=' + encodeURIComponent(content) + '&url=' + encodeURIComponent(url) + '&pic=' + pic + "&appkey=" + appkey, '_blank', 'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
//    void (0);

    var appkey = "1509936684";
    //appkey = "1342253321";
    var sUrl = 'http://v.t.sina.com.cn/share/share.php';
    var params = {
        url: location.href,
        title: content,
        pic: pic,
        appkey: appkey
    };
    var win = new shareWindow(sUrl, params);
    win.open();
}